Hi again,
Appending to an already existing file is not to hard:
Code:
#!/usr/bin/perl -w
my @lines;
# Infiles
my $file1="data1.log";
my $file2="data2.log";
# Outfile
my $nf="nf.log";
# Open outfile
open NEWFILE, ">$nf" or die "Can't open $nf";
# Open first infile and write to outfile
open (FILE, "$file1") or die ("can't open this: $!");
@lines=<FILE>;
print NEWFILE @lines;
close (FILE) or die "FILE can't be closed: $!";
# Open and append second infile to outfile
open (FILE, "$file2") or die ("can't open this: $!");
@lines=<FILE>;
print NEWFILE @lines;
close (FILE) or die "FILE can't be closed: $!";
# Close outfile
close NEWFILE;
The above code will put lines from data1.log into nf.log and then put (append) lines from data2.log to nf.log. In the end nf.log holds both data1.log and data2.log lines.
This is just one way of doing what you ask. Depending on what you need to do with the lines from data1 and/or data2 other solutions could be better/faster. Here's a variation on the same script:
Code:
#!/usr/bin/perl -w
# Infiles
my $file1="data1";
my $file2="data2";
# Outfile
my $nf="nf.log";
# Open first infile and read contens
open (FILE, "$file1") or die ("can't open this: $!");
my @lines01=<FILE>;
close (FILE) or die "FILE can't be closed: $!";
# Open second file and read contens
open (FILE, "$file2") or die ("can't open this: $!");
my @lines02=<FILE>;
close (FILE) or die "FILE can't be closed: $!";
# Open outfile
open NEWFILE, ">$nf" or die "Can't open $nf";
# print content of both files to outfile.
print NEWFILE @lines01;
print NEWFILE @lines02;
# Close outfile
close NEWFILE;